package com.example.project01.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.leon.model.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.sql.Timestamp;

@Data
public class Banner implements Model {

    @Schema(description = "主键ID")
    private Long id;
    @Schema(description = "图片")
    private String image;
    @Schema(description = "轮播图排序")
    private Integer sortOrder;
    @Schema(description = "包推荐 数据包推荐/语音包推荐")
    private String module;
    @Schema(description = "类型 广告可跳转/广告不可跳转")
    private String type;
    @Schema(description = "状态 当前图片是否生效")
    private String status;
    @Schema(description = "跳转地址")
    private String url;
    @Schema(description = "banner名字")
    private String name;
    @Schema(description = "中国 欧洲 韩国")
    private String language;
    @Schema(description = "当前banner背景图")
    private String bannerBackground;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "创建时间")
    private Timestamp createdAt;

    @Getter
    @AllArgsConstructor
    public enum ModuleEnum {
        PACKETREC("数据包推荐"),
        VOICEREC("语音包推荐");
        private final String description;
    }

    @Getter
    @AllArgsConstructor
    public enum TypeEnum {
        ADVERT("广告可跳转"),
        NO_ADVERT("广告不可跳转");
        private final String description;
    }

    @Getter
    @AllArgsConstructor
    public enum StatusEnum {
        USING( "图片生效"),
        UNUSED( "图片不生效");
        private final String description;
    }

    public void isModule(String banner) {
        if (ModuleEnum.VOICEREC.name().equals(banner)) {
            this.setModule(ModuleEnum.VOICEREC.name());
        } else if (ModuleEnum.PACKETREC.name().equals(banner)) {
            this.setModule(ModuleEnum.PACKETREC.name());
        } else {
            this.setModule(null);
        }
    }

    public void isType(String banner) {
        if (TypeEnum.ADVERT.name().equals(banner)) {
            this.setType(TypeEnum.ADVERT.name());
        } else if (TypeEnum.NO_ADVERT.name().equals(banner)) {
            this.setType(TypeEnum.NO_ADVERT.name());
        } else {
            this.setType(null);
        }
    }

    public void isStatus(String banner) {
        if (StatusEnum.USING.name().equals(banner)) {
           this.setStatus(StatusEnum.USING.name());
        } else if (StatusEnum.UNUSED.name().equals(banner)) {
            this.setStatus(StatusEnum.UNUSED.name());
        } else {
            this.setStatus(null);
        }
    }
}
